home *** CD-ROM | disk | FTP | other *** search
- /* ftoa.c */
-
- char * _cdecl _fcvt(double, int, int *, int *);
-
- static int nDec, nSign;
-
- /************************************************************************
- * FloatToString: *
- * This function converts floating point numbers to strings. It returns *
- * a pointer to a string containing the converted number. *
- * *
- * Parameter Type/Description *
- * *
- * lfNumber double Contains the number to be converted. *
- * *
- * szBuffer LPSTR Points to a buffer which will recieve the *
- * string equivalent of the number. *
- * *
- * wPlaces WORD Contains the number of decimal places the *
- * number should be converted to. *
- * *
- ************************************************************************/
-
- LPSTR WINAPI FloatToString ( double lfNumber, LPSTR lpszBuffer, WORD wPlaces )
- {
- /******************************************************************
- * Local Variables: *
- * LPSTR lpNum is used to store the address of the converted *
- * number returned by _fcvt. *
- ******************************************************************/
-
- LPSTR lpNum;
-
- /******************************************************************
- * Convert Number: *
- * _fcvt is called to convert the number into a string. The return *
- * value is stored in lpNum. The storage buffer is zeroed. *
- ******************************************************************/
-
- lpNum=(LPSTR)_fcvt ( lfNumber, wPlaces, &nDec, &nSign );
- *lpszBuffer=EOS;
-
- /******************************************************************
- * Put In Minus Sign: *
- * If nSign is non_zero then the number is negative and a minus *
- * sign is put at the start of the return string. *
- ******************************************************************/
-
- if ( nSign )
- lstrcat ( lpszBuffer, "-" );
-
- /******************************************************************
- * Process Numbers: *
- * If nDec is less than or equal to zero then the number converted *
- * is less than one. A zero and a decimal point are added to the *
- * return string and then as many zeros as necessary are also *
- * added. The number string is then added. *
- * If nDec is greater than zero then the _fcvt string is copied *
- * into the return string upto the nDec'th character. A decimal *
- * point is then added and the remainder of the _fcvt string is *
- * added. *
- * ftoa then returns lpszBuffer, the address of the start of the *
- * return string. *
- ******************************************************************/
-
- if ( nDec<=0 )
- {
- lstrcat ( lpszBuffer, "0." );
-
- for (;nDec++;)
- lstrcat ( lpszBuffer, "0" );
-
- lstrcat ( lpszBuffer, lpNum );
- }
- else
- {
- lstrncat ( lpszBuffer, lpNum, (WORD)nDec );
- lstrcat ( lpszBuffer, "." );
- lstrcat ( lpszBuffer, lpNum+nDec );
- }
-
- return lpszBuffer;
- }
-
-
- LPSTR WINAPI lstrncat ( LPSTR lpszDest,
- LPSTR lpszSrc,
- WORD wChars )
- {
- LPSTR lpszRet=lpszDest;
-
- lpszDest+=lstrlen ( lpszDest );
-
- for (;*lpszSrc && wChars;wChars--)
- *lpszDest++=*lpszSrc++;
-
- *lpszDest=EOS;
- return lpszRet;
- }
-